//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitee_triger

import (
	"fmt"
	"testing"
)

const _PR_HOOK_DATA = `
{
  "iid": 1,
  "url": "https://gitee.com/oschina/git-osc/pulls/6",
  "sign": "",
  "state": "open",
  "title": "这是一条测试 Pull Request 类型 WebHook 触发的推送",
  "action": "open",
  "author": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "time": "2020-04-15T21:09:40+08:00",
    "type": "User",
    "email": "gitee@gitee.com",
    "login": "oschina-org",
    "html_url": "https://gitee.com/oschina-org",
    "username": "oschina-org",
    "user_name": "oschina-org",
    "avatar_url": "https://gitee.com/assets/favicon.ico",
    "site_admin": false
  },
  "number": 1,
  "sender": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "time": "2020-04-15T21:09:40+08:00",
    "type": "User",
    "email": "gitee@gitee.com",
    "login": "oschina-org",
    "html_url": "https://gitee.com/oschina-org",
    "username": "oschina-org",
    "user_name": "oschina-org",
    "avatar_url": "https://gitee.com/assets/favicon.ico",
    "site_admin": false
  },
  "hook_id": 1457589,
  "project": {
    "id": 151,
    "url": "https://gitee.com/oschina/git-osc",
    "fork": false,
    "name": "Gitee FeedBack",
    "path": "git-osc",
    "owner": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "git_url": "git://gitee.com:oschina/git-osc.git",
    "private": false,
    "ssh_url": "git@gitee.com:oschina/git-osc.git",
    "svn_url": "svn://gitee.com/oschina/git-osc",
    "has_wiki": true,
    "html_url": "https://gitee.com/oschina/git-osc",
    "language": "ruby",
    "clone_url": "https://gitee.com/oschina/git-osc.git",
    "full_name": "oschina/git-osc",
    "has_pages": false,
    "namespace": "oschina",
    "pushed_at": "2020-04-15T21:09:40+08:00",
    "created_at": "2020-04-15T21:09:40+08:00",
    "has_issues": true,
    "updated_at": "2020-04-15T21:09:40+08:00",
    "description": "",
    "forks_count": 0,
    "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
    "git_svn_url": "svn://gitee.com/oschina/git-osc",
    "git_http_url": "https://gitee.com/oschina/git-osc.git",
    "default_branch": "master",
    "watchers_count": 12,
    "stargazers_count": 11,
    "open_issues_count": 0,
    "name_with_namespace": "OSCHINA/git-osc",
    "path_with_namespace": "oschina/git-osc"
  },
  "hook_url": "http://175.178.105.150:9088/",
  "password": "123123123",
  "hook_name": "merge_request_hooks",
  "languages": [
    "Java",
    "Ruby"
  ],
  "enterprise": {
    "url": "https://gitee.com/oschina",
    "name": "OSCHINA"
  },
  "repository": {
    "id": 151,
    "url": "https://gitee.com/oschina/git-osc",
    "fork": false,
    "name": "Gitee FeedBack",
    "path": "git-osc",
    "owner": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "git_url": "git://gitee.com:oschina/git-osc.git",
    "private": false,
    "ssh_url": "git@gitee.com:oschina/git-osc.git",
    "svn_url": "svn://gitee.com/oschina/git-osc",
    "has_wiki": true,
    "html_url": "https://gitee.com/oschina/git-osc",
    "language": "ruby",
    "clone_url": "https://gitee.com/oschina/git-osc.git",
    "full_name": "oschina/git-osc",
    "has_pages": false,
    "namespace": "oschina",
    "pushed_at": "2020-04-15T21:09:40+08:00",
    "created_at": "2020-04-15T21:09:40+08:00",
    "has_issues": true,
    "updated_at": "2020-04-15T21:09:40+08:00",
    "description": "",
    "forks_count": 0,
    "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
    "git_svn_url": "svn://gitee.com/oschina/git-osc",
    "git_http_url": "https://gitee.com/oschina/git-osc.git",
    "default_branch": "master",
    "watchers_count": 12,
    "stargazers_count": 11,
    "open_issues_count": 0,
    "name_with_namespace": "OSCHINA/git-osc",
    "path_with_namespace": "oschina/git-osc"
  },
  "updated_by": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "time": "2020-04-15T21:09:40+08:00",
    "type": "User",
    "email": "gitee@gitee.com",
    "login": "oschina-org",
    "html_url": "https://gitee.com/oschina-org",
    "username": "oschina-org",
    "user_name": "oschina-org",
    "avatar_url": "https://gitee.com/assets/favicon.ico",
    "site_admin": false
  },
  "action_desc": "open",
  "source_repo": {
    "project": {
      "id": 151,
      "url": "https://gitee.com/oschina/git-osc",
      "fork": false,
      "name": "Gitee FeedBack",
      "path": "git-osc",
      "owner": {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      },
      "git_url": "git://gitee.com:oschina/git-osc.git",
      "private": false,
      "ssh_url": "git@gitee.com:oschina/git-osc.git",
      "svn_url": "svn://gitee.com/oschina/git-osc",
      "has_wiki": true,
      "html_url": "https://gitee.com/oschina/git-osc",
      "language": "ruby",
      "clone_url": "https://gitee.com/oschina/git-osc.git",
      "full_name": "oschina/git-osc",
      "has_pages": false,
      "namespace": "oschina",
      "pushed_at": "2020-04-15T21:09:40+08:00",
      "created_at": "2020-04-15T21:09:40+08:00",
      "has_issues": true,
      "updated_at": "2020-04-15T21:09:40+08:00",
      "description": "",
      "forks_count": 0,
      "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
      "git_svn_url": "svn://gitee.com/oschina/git-osc",
      "git_http_url": "https://gitee.com/oschina/git-osc.git",
      "default_branch": "master",
      "watchers_count": 12,
      "stargazers_count": 11,
      "open_issues_count": 0,
      "name_with_namespace": "OSCHINA/git-osc",
      "path_with_namespace": "oschina/git-osc"
    },
    "repository": {
      "id": 151,
      "url": "https://gitee.com/oschina/git-osc",
      "fork": false,
      "name": "Gitee FeedBack",
      "path": "git-osc",
      "owner": {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      },
      "git_url": "git://gitee.com:oschina/git-osc.git",
      "private": false,
      "ssh_url": "git@gitee.com:oschina/git-osc.git",
      "svn_url": "svn://gitee.com/oschina/git-osc",
      "has_wiki": true,
      "html_url": "https://gitee.com/oschina/git-osc",
      "language": "ruby",
      "clone_url": "https://gitee.com/oschina/git-osc.git",
      "full_name": "oschina/git-osc",
      "has_pages": false,
      "namespace": "oschina",
      "pushed_at": "2020-04-15T21:09:40+08:00",
      "created_at": "2020-04-15T21:09:40+08:00",
      "has_issues": true,
      "updated_at": "2020-04-15T21:09:40+08:00",
      "description": "",
      "forks_count": 0,
      "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
      "git_svn_url": "svn://gitee.com/oschina/git-osc",
      "git_http_url": "https://gitee.com/oschina/git-osc.git",
      "default_branch": "master",
      "watchers_count": 12,
      "stargazers_count": 11,
      "open_issues_count": 0,
      "name_with_namespace": "OSCHINA/git-osc",
      "path_with_namespace": "oschina/git-osc"
    }
  },
  "target_repo": {
    "project": {
      "id": 151,
      "url": "https://gitee.com/oschina/git-osc",
      "fork": false,
      "name": "Gitee FeedBack",
      "path": "git-osc",
      "owner": {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      },
      "git_url": "git://gitee.com:oschina/git-osc.git",
      "private": false,
      "ssh_url": "git@gitee.com:oschina/git-osc.git",
      "svn_url": "svn://gitee.com/oschina/git-osc",
      "has_wiki": true,
      "html_url": "https://gitee.com/oschina/git-osc",
      "language": "ruby",
      "clone_url": "https://gitee.com/oschina/git-osc.git",
      "full_name": "oschina/git-osc",
      "has_pages": false,
      "namespace": "oschina",
      "pushed_at": "2020-04-15T21:09:40+08:00",
      "created_at": "2020-04-15T21:09:40+08:00",
      "has_issues": true,
      "updated_at": "2020-04-15T21:09:40+08:00",
      "description": "",
      "forks_count": 0,
      "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
      "git_svn_url": "svn://gitee.com/oschina/git-osc",
      "git_http_url": "https://gitee.com/oschina/git-osc.git",
      "default_branch": "master",
      "watchers_count": 12,
      "stargazers_count": 11,
      "open_issues_count": 0,
      "name_with_namespace": "OSCHINA/git-osc",
      "path_with_namespace": "oschina/git-osc"
    },
    "repository": {
      "id": 151,
      "url": "https://gitee.com/oschina/git-osc",
      "fork": false,
      "name": "Gitee FeedBack",
      "path": "git-osc",
      "owner": {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      },
      "git_url": "git://gitee.com:oschina/git-osc.git",
      "private": false,
      "ssh_url": "git@gitee.com:oschina/git-osc.git",
      "svn_url": "svn://gitee.com/oschina/git-osc",
      "has_wiki": true,
      "html_url": "https://gitee.com/oschina/git-osc",
      "language": "ruby",
      "clone_url": "https://gitee.com/oschina/git-osc.git",
      "full_name": "oschina/git-osc",
      "has_pages": false,
      "namespace": "oschina",
      "pushed_at": "2020-04-15T21:09:40+08:00",
      "created_at": "2020-04-15T21:09:40+08:00",
      "has_issues": true,
      "updated_at": "2020-04-15T21:09:40+08:00",
      "description": "",
      "forks_count": 0,
      "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
      "git_svn_url": "svn://gitee.com/oschina/git-osc",
      "git_http_url": "https://gitee.com/oschina/git-osc.git",
      "default_branch": "master",
      "watchers_count": 12,
      "stargazers_count": 11,
      "open_issues_count": 0,
      "name_with_namespace": "OSCHINA/git-osc",
      "path_with_namespace": "oschina/git-osc"
    }
  },
  "target_user": {
    "id": 1,
    "url": "https://gitee.com/oschina-org",
    "name": "Gitee",
    "email": "gitee@gitee.com",
    "username": "oschina-org",
    "user_name": "oschina-org"
  },
  "merge_status": "unchecked",
  "pull_request": {
    "id": 167750879,
    "base": {
      "ref": "master",
      "sha": "3a6902040b2fd1e240315a84611d36eef14b4f2f",
      "repo": {
        "id": 151,
        "url": "https://gitee.com/oschina/git-osc",
        "fork": false,
        "name": "Gitee FeedBack",
        "path": "git-osc",
        "owner": {
          "id": 1,
          "url": "https://gitee.com/oschina-org",
          "name": "Gitee",
          "time": "2020-04-15T21:09:40+08:00",
          "type": "User",
          "email": "gitee@gitee.com",
          "login": "oschina-org",
          "html_url": "https://gitee.com/oschina-org",
          "username": "oschina-org",
          "user_name": "oschina-org",
          "avatar_url": "https://gitee.com/assets/favicon.ico",
          "site_admin": false
        },
        "git_url": "git://gitee.com:oschina/git-osc.git",
        "private": false,
        "ssh_url": "git@gitee.com:oschina/git-osc.git",
        "svn_url": "svn://gitee.com/oschina/git-osc",
        "has_wiki": true,
        "html_url": "https://gitee.com/oschina/git-osc",
        "language": "ruby",
        "clone_url": "https://gitee.com/oschina/git-osc.git",
        "full_name": "oschina/git-osc",
        "has_pages": false,
        "namespace": "oschina",
        "pushed_at": "2020-04-15T21:09:40+08:00",
        "created_at": "2020-04-15T21:09:40+08:00",
        "has_issues": true,
        "updated_at": "2020-04-15T21:09:40+08:00",
        "description": "",
        "forks_count": 0,
        "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
        "git_svn_url": "svn://gitee.com/oschina/git-osc",
        "git_http_url": "https://gitee.com/oschina/git-osc.git",
        "default_branch": "master",
        "watchers_count": 12,
        "stargazers_count": 11,
        "open_issues_count": 0,
        "name_with_namespace": "OSCHINA/git-osc",
        "path_with_namespace": "oschina/git-osc"
      },
      "user": {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      },
      "label": "gitee:master"
    },
    "head": {
      "ref": "login_should_complete_info",
      "sha": "ad2f7b1729eea675cd44da48f5e53abdf8f242a8",
      "repo": {
        "id": 151,
        "url": "https://gitee.com/oschina/git-osc",
        "fork": false,
        "name": "Gitee FeedBack",
        "path": "git-osc",
        "owner": {
          "id": 1,
          "url": "https://gitee.com/oschina-org",
          "name": "Gitee",
          "time": "2020-04-15T21:09:40+08:00",
          "type": "User",
          "email": "gitee@gitee.com",
          "login": "oschina-org",
          "html_url": "https://gitee.com/oschina-org",
          "username": "oschina-org",
          "user_name": "oschina-org",
          "avatar_url": "https://gitee.com/assets/favicon.ico",
          "site_admin": false
        },
        "git_url": "git://gitee.com:oschina/git-osc.git",
        "private": false,
        "ssh_url": "git@gitee.com:oschina/git-osc.git",
        "svn_url": "svn://gitee.com/oschina/git-osc",
        "has_wiki": true,
        "html_url": "https://gitee.com/oschina/git-osc",
        "language": "ruby",
        "clone_url": "https://gitee.com/oschina/git-osc.git",
        "full_name": "oschina/git-osc",
        "has_pages": false,
        "namespace": "oschina",
        "pushed_at": "2020-04-15T21:09:40+08:00",
        "created_at": "2020-04-15T21:09:40+08:00",
        "has_issues": true,
        "updated_at": "2020-04-15T21:09:40+08:00",
        "description": "",
        "forks_count": 0,
        "git_ssh_url": "git@gitee.com:oschina/git-osc.git",
        "git_svn_url": "svn://gitee.com/oschina/git-osc",
        "git_http_url": "https://gitee.com/oschina/git-osc.git",
        "default_branch": "master",
        "watchers_count": 12,
        "stargazers_count": 11,
        "open_issues_count": 0,
        "name_with_namespace": "OSCHINA/git-osc",
        "path_with_namespace": "oschina/git-osc"
      },
      "user": {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      },
      "label": "gitee:login_should_complete_info"
    },
    "user": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "state": "open",
    "title": "这是一条测试 Pull Request 类型 WebHook 触发的推送",
    "labels": [
      {
        "id": 827033694,
        "name": "bug",
        "color": "d73a4a"
      }
    ],
    "merged": false,
    "number": 1,
    "commits": 1,
    "testers": [

    ],
    "assignee": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "comments": 0,
    "diff_url": "https://gitee.com/oschina/git-osc/pulls/6.diff",
    "html_url": "https://gitee.com/oschina/git-osc/pulls/6",
    "additions": 7,
    "assignees": [
      {
        "id": 1,
        "url": "https://gitee.com/oschina-org",
        "name": "Gitee",
        "time": "2020-04-15T21:09:40+08:00",
        "type": "User",
        "email": "gitee@gitee.com",
        "login": "oschina-org",
        "html_url": "https://gitee.com/oschina-org",
        "username": "oschina-org",
        "user_name": "oschina-org",
        "avatar_url": "https://gitee.com/assets/favicon.ico",
        "site_admin": false
      }
    ],
    "deletions": 0,
    "languages": [
      "Java",
      "Ruby"
    ],
    "milestone": {
      "id": 1,
      "state": "open",
      "title": "问题反馈",
      "number": 1,
      "html_url": "https://gitee.com/oschina/gitee/milestones/14143",
      "created_at": "2020-04-15T21:09:40+08:00",
      "updated_at": "2020-04-15T21:09:40+08:00",
      "open_issues": 13,
      "closed_issues": 31
    },
    "need_test": false,
    "patch_url": "https://gitee.com/oschina/git-osc/pulls/6.patch",
    "created_at": "2020-04-15T21:09:40+08:00",
    "updated_at": "2020-04-15T21:09:40+08:00",
    "updated_by": {
      "id": 1,
      "url": "https://gitee.com/oschina-org",
      "name": "Gitee",
      "time": "2020-04-15T21:09:40+08:00",
      "type": "User",
      "email": "gitee@gitee.com",
      "login": "oschina-org",
      "html_url": "https://gitee.com/oschina-org",
      "username": "oschina-org",
      "user_name": "oschina-org",
      "avatar_url": "https://gitee.com/assets/favicon.ico",
      "site_admin": false
    },
    "need_review": false,
    "merge_status": "unchecked",
    "stale_labels": [

    ],
    "changed_files": 1,
    "merge_commit_sha": "ad2f7b1729eea675cd44da48f5e53abdf8f242a8"
  },
  "source_branch": "login_should_complete_info",
  "target_branch": "master",
  "merge_commit_sha": "ad2f7b1729eea675cd44da48f5e53abdf8f242a8"
}
`

func TestExtractPrHookAttr(t *testing.T) {
	attrList, err := ExtractPrHookAttr([]byte(_PR_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
